DROP FUNCTION IF EXISTS usp_[%tablename%]_del(bigint);
CREATE OR REPLACE FUNCTION usp_[%tablename%]_del (
  param_id BIGINT,
  hard bit
) RETURNS void AS $$
-- Delete (soft) record in [%tablename%].
--  [%datestamp%] - auto generated
BEGIN  
  if (hard = 1) THEN
	  BEGIN
		DELETE FROM [%tablename%] WHERE id = param_id;
	  END;
  ELSE
	  BEGIN    
		  UPDATE [%tablename%] 
		  SET 
			is_deleted = 1,
			deleted_dt=now()
		  WHERE
			id = param_id; 
	  END;
	END IF; 
END;
$$ LANGUAGE plpgsql;
